/*     */ package com.zimbra.cs.mailbox;
/*     */ 
/*     */ import com.google.common.base.Objects;
/*     */ import com.google.common.base.Objects.ToStringHelper;
/*     */ import com.zimbra.common.mailbox.Color;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.db.DbMailItem;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Mountpoint
/*     */   extends Folder
/*     */ {
/*     */   private String mOwnerId;
/*     */   private int mRemoteId;
/*     */   private String mRemoteUuid;
/*     */   private boolean mReminderEnabled;
/*     */   
/*     */   Mountpoint(Mailbox mbox, MailItem.UnderlyingData ud)
/*     */     throws ServiceException
/*     */   {
/*  39 */     this(mbox, ud, false);
/*     */   }
/*     */   
/*     */   Mountpoint(Mailbox mbox, MailItem.UnderlyingData ud, boolean skipCache) throws ServiceException {
/*  43 */     super(mbox, ud, skipCache);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public String getOwnerId()
/*     */   {
/*  51 */     return this.mOwnerId;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public int getRemoteId()
/*     */   {
/*  59 */     return this.mRemoteId;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public String getRemoteUuid()
/*     */   {
/*  66 */     return this.mRemoteUuid;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public ItemId getTarget()
/*     */   {
/*  75 */     return new ItemId(this.mOwnerId, this.mRemoteId);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean isReminderEnabled()
/*     */   {
/*  83 */     return this.mReminderEnabled;
/*     */   }
/*     */   
/*     */   public boolean isLocal()
/*     */   {
/*  88 */     return getOwnerId().equals(getMailbox().getAccountId());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   void grantAccess(String liquidId, byte type, short rights, boolean inherit)
/*     */     throws ServiceException
/*     */   {
/*  96 */     throw ServiceException.PERM_DENIED("you may not share the mounted folder " + getPath());
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   void revokeAccess(String liquidId) {}
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 109 */   boolean canHaveChildren() { return false; }
/* 110 */   boolean trackUnread() { return false; }
/* 111 */   boolean canParent(MailItem child) { return false; }
/* 112 */   boolean canContain(MailItem child) { return false; }
/* 113 */   boolean canContain(MailItem.Type type) { return false; }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   static Mountpoint create(int id, String uuid, Folder parent, String name, String ownerId, int remoteId, String remoteUuid, MailItem.Type view, int flags, Color color, boolean reminderEnabled, MailItem.CustomMetadata custom)
/*     */     throws ServiceException
/*     */   {
/* 146 */     if ((parent == null) || (ownerId == null) || (remoteId <= 0)) {
/* 147 */       throw ServiceException.INVALID_REQUEST("invalid parameters when creating mountpoint", null);
/*     */     }
/* 149 */     if (!parent.canAccess((short)4)) {
/* 150 */       throw ServiceException.PERM_DENIED("you do not have sufficient permissions on the parent folder");
/*     */     }
/* 152 */     if (!parent.canContain(MailItem.Type.MOUNTPOINT)) {
/* 153 */       throw MailServiceException.CANNOT_CONTAIN();
/*     */     }
/* 155 */     name = validateItemName(name);
/* 156 */     if (parent.findSubfolder(name) != null) {
/* 157 */       throw MailServiceException.ALREADY_EXISTS(name);
/*     */     }
/* 159 */     Mailbox mbox = parent.getMailbox();
/*     */     
/* 161 */     MailItem.UnderlyingData data = new MailItem.UnderlyingData();
/* 162 */     data.uuid = uuid;
/* 163 */     data.id = id;
/* 164 */     data.type = MailItem.Type.MOUNTPOINT.toByte();
/* 165 */     data.folderId = parent.getId();
/* 166 */     data.parentId = data.folderId;
/* 167 */     data.date = mbox.getOperationTimestamp();
/* 168 */     data.setFlags(flags & Flag.FLAGS_FOLDER);
/* 169 */     data.name = name;
/* 170 */     data.setSubject(name);
/* 171 */     data.metadata = encodeMetadata(color, 1, 1, custom, view, ownerId, remoteId, remoteUuid, reminderEnabled);
/* 172 */     data.contentChanged(mbox);
/* 173 */     ZimbraLog.mailop.info("Adding Mountpoint %s: id=%d, parentId=%d, parentName=%s.", new Object[] { name, Integer.valueOf(data.id), Integer.valueOf(parent.getId()), parent.getName() });
/*     */     
/* 175 */     new DbMailItem(mbox).create(data);
/*     */     
/* 177 */     Mountpoint mpt = new Mountpoint(mbox, data);
/* 178 */     mpt.finishCreation(parent);
/* 179 */     return mpt;
/*     */   }
/*     */   
/*     */   void delete(boolean writeTombstones) throws ServiceException
/*     */   {
/* 184 */     if (!getFolder().canAccess((short)8))
/* 185 */       throw ServiceException.PERM_DENIED("you do not have sufficient permissions on the parent folder");
/* 186 */     super.delete(writeTombstones);
/*     */   }
/*     */   
/*     */   void decodeMetadata(Metadata meta)
/*     */     throws ServiceException
/*     */   {
/* 192 */     super.decodeMetadata(meta);
/* 193 */     this.mOwnerId = meta.get("aid");
/* 194 */     this.mRemoteId = ((int)meta.getLong("id"));
/* 195 */     this.mRemoteUuid = meta.get("ruuid", null);
/* 196 */     this.mReminderEnabled = meta.getBool("rem", false);
/*     */   }
/*     */   
/*     */   Metadata encodeMetadata(Metadata meta)
/*     */   {
/* 201 */     return encodeMetadata(meta, this.mRGBColor, this.mMetaVersion, this.mVersion, this.mExtendedData, this.attributes, this.defaultView, this.mOwnerId, this.mRemoteId, this.mRemoteUuid, this.mReminderEnabled);
/*     */   }
/*     */   
/*     */   private static String encodeMetadata(Color color, int metaVersion, int version, MailItem.CustomMetadata custom, MailItem.Type view, String owner, int remoteId, String remoteUuid, boolean reminderEnabled)
/*     */   {
/* 206 */     MailItem.CustomMetadata.CustomMetadataList extended = custom == null ? null : custom.asList();
/* 207 */     return encodeMetadata(new Metadata(), color, metaVersion, version, extended, (byte)0, view, owner, remoteId, remoteUuid, reminderEnabled).toString();
/*     */   }
/*     */   
/*     */   static Metadata encodeMetadata(Metadata meta, Color color, int metaVersion, int version, MailItem.CustomMetadata.CustomMetadataList extended, byte attrs, MailItem.Type view, String owner, int remoteId, String remoteUuid, boolean reminderEnabled)
/*     */   {
/* 212 */     meta.put("aid", owner);
/* 213 */     meta.put("id", remoteId);
/* 214 */     meta.put("ruuid", remoteUuid);
/* 215 */     if (reminderEnabled)
/* 216 */       meta.put("rem", reminderEnabled);
/* 217 */     return Folder.encodeMetadata(meta, color, metaVersion, version, extended, attrs, view, null, null, 0, 0L, 0, 0, 0, 0, 0, null, false, -1);
/*     */   }
/*     */   
/*     */   public String toString()
/*     */   {
/* 222 */     Objects.ToStringHelper helper = Objects.toStringHelper(this);
/* 223 */     helper.add("n", getName());
/* 224 */     appendCommonMembers(helper);
/* 225 */     helper.add("attributes", this.attributes);
/* 226 */     helper.add("reminder", this.mReminderEnabled);
/* 227 */     return helper.toString();
/*     */   }
/*     */   
/*     */ 
/*     */   void enableReminder(boolean enable)
/*     */     throws ServiceException
/*     */   {
/* 234 */     if (!isMutable()) {
/* 235 */       throw MailServiceException.IMMUTABLE_OBJECT(this.mId);
/*     */     }
/* 237 */     if (!canAccess((short)2)) {
/* 238 */       throw ServiceException.PERM_DENIED("you do not have the required rights on the mountpoint");
/*     */     }
/* 240 */     if (this.mReminderEnabled == enable) {
/* 241 */       return;
/*     */     }
/* 243 */     markItemModified(16777216);
/* 244 */     this.mReminderEnabled = enable;
/* 245 */     saveMetadata();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   void setRemoteInfo(String ownerId, int remoteId)
/*     */     throws ServiceException
/*     */   {
/* 257 */     if ((this.mOwnerId.equalsIgnoreCase(ownerId)) && (this.mRemoteId == remoteId))
/*     */     {
/* 259 */       return;
/*     */     }
/* 261 */     this.mOwnerId = ownerId;
/* 262 */     this.mRemoteId = remoteId;
/* 263 */     markItemModified(524288);
/* 264 */     saveMetadata();
/*     */   }
/*     */   
/*     */   protected void checkItemCreationAllowed()
/*     */     throws ServiceException
/*     */   {}
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/Mountpoint.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */